/**
 * problem_040.cpp
 * Copyright (C) 2011 - xrose
 */

#include <iostream>
#include <sstream>
#include <math.h>
using namespace std;
int POWERINT[10] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
int nodigit(int abc)
{
    for(int i=1; i<10; i++)
    {
        if((POWERINT[i-1]<=abc)&&(POWERINT[i]>abc)) return i;
    }
}
int index(int p, int idx)
{
    //p has n number of digit
    //idx is index of an digit of p from the end
    int n = nodigit(p);
    if(n<idx) return 0;
    int tmp = p%(POWERINT[idx]);
    return tmp/POWERINT[idx-1];
}
int d(int n)
{
    int cnt = 0;
    int p = 0;
    while(cnt<n)
    {
        p++;
        cnt += nodigit(p);
    }
//    cnt -n
    cout<<"p = "<<p<<" cnt = "<<cnt<<endl;

    return index(p, cnt-n+1);
}
int main (int argc, char const* argv[])
{
    cout<<d(10)<<endl;
//    cout<<d(100)<<endl;
//    cout<<d(1000)<<endl;
//    cout<<d(10000)<<endl;
//    cout<<d(100000)<<endl;
//    cout<<d(1000000)<<endl;
//    cout<<index(123456, 4);
    int prod = 1;
    for(int i = 1; i<=6; i++)
    {
        prod*=d(POWERINT[i]);
    }
    cout<<"++"<<prod;
	return 0;
}
//----
//    stringstream ss;
//    ss<<1;
//    int cnt= 1;
//    while(ss.str().length() <= 1000000)
//    {
//        cnt++;
//        ss<<cnt;
////        cout<<cnt<<endl;
//        cout<<ss.str().length()<<endl;
//    }
//    cout<<ss.str().length();
